package com.hh.dao;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;

public class HealthinformationpeopleDao {

    public final static String cfn = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    public final static String url = "jdbc:sqlserver://212.129.155.194:1433;DatabaseName=jcyy_test";
    public final static String user = "sa";
    public final static String password = "ZJzhengg@163.com";
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public JSONArray getHealthinformationpeople(String mzhm) {
        Connection con = null;
        PreparedStatement statement = null;
        ResultSet res = null;
        JSONArray array = new JSONArray();
        try {
            Class.forName(cfn);
            con = DriverManager.getConnection(url, user, password);
            String sql = "select * from Health_informationpeople h where h.mzhm ="+mzhm ;
            System.out.println(sql);
            statement = con.prepareStatement(sql);
            res = statement.executeQuery();
            while (res.next()) {
                JSONObject o = new JSONObject();
                o.put("id",res.getString("id"));
                o.put("touxiang",res.getString("touxiang"));
                o.put("name",res.getString("name"));
                o.put("sex",res.getString("sex"));
                o.put("age",res.getString("age"));
                o.put("birthday",res.getString("birthday"));
                o.put("address",res.getString("address"));
                o.put("phone",res.getString("phone"));
                o.put("emergencycontact",res.getString("emergencycontact"));
                o.put("emergencycontactphone",res.getString("emergencycontactphone"));
                o.put("familydoctor",res.getString("familydoctor"));
                o.put("physicalcondition",res.getString("physicalcondition"));
                o.put("sleep",res.getString("sleep"));
                o.put("livingenvironment",res.getString("livingenvironment"));
                o.put("activity",res.getString("activity"));
                o.put("eatinghabits",res.getString("eatinghabits"));
                o.put("mzhm",res.getString("mzhm"));
                array.add(o);
            }
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        } finally {
            try {
                if (res != null) res.close();
                if (statement != null) statement.close();
                if (con != null) con.close();
            } catch (Exception e2) {
                // TODO: handle exception
                e2.printStackTrace();
            }
        }
        return array;
    }


}

